class AudioSound {
  constructor(src) {
    this.audio = document.createElement('audio');
    // this.audio.setAttribute('loop', 'loop');
  }

  setSrc(src) {
    if (this.audio.canPlayType('audio/mp3')) {
      this.audio.src = `${src}.mp3`;
    } else if (this.audio.canPlayType('audio/ogg')) {
      this.audio.src = `${src}.ogg`;
    } else {
      this.audio.src = `${src}.wav`;
    }
  }

  play() {
    //this.audio.currentTime = 0;
    this.audio.play();
  }

  stop() {
    this.audio.pause();
    //this.audio.currentTime = 0;
  }

  replay() {
    this.audio.currentTime = 0;
    this.audio.play();
  }
}

export default function audioPlay() {
  return new AudioSound();
}
